
DW = {}

DW.RefreshTime = 0
DW.Force = Vector( 0, 0, 0 )

DW.Props = {}

DW.Wind = {}

DW.Wind.Max = 360
DW.Wind.Min = 50

function DW.PerformWinds()

	if CurTime() > DW.RefreshTime then
	
		DW.RefreshTime = CurTime() + math.random( 1, 5 )

		for k,v in pairs(DW.Props) do

			if tostring(v) == "[NULL Entity]" then 
				table.remove(DW.Props, k) 
				DW.Print("Corruption data in DW.Props table, removing corrupt prop.")
				return false
			end
			
			local phys = v:GetPhysicsObject()
			
			phys:SetVelocity( DW.Force )
			
		end
		
	end
	
end
hook.Add("Think", "DynamWindsThink", DW.PerformWinds)

function DW.SetWindSpeed()

	DW.Force = Vector( math.Rand(DW.Wind.Min, DW.Wind.Max), math.Rand(DW.Wind.Min, DW.Wind.Max), 0)
	
end
timer.Create("DW.RefreshForce", 3 * 60, 0, DW.SetWindSpeed)
DW.SetWindSpeed()

function DW.AddProp(p, _, arg)

	local tr = p:GetEyeTrace()
	local ent = tr.Entity
	
	if ent:IsValid() and !ent:IsPlayer() then
	
		table.insert(DW.Props, ent)
		
	end
	
end
concommand.Add("DW_AddProp", DW.AddProp)

function DW.Print( msg )

	print("[DYNAMWINDS] " .. msg )
	
end